<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html lang="en" ng-app="myApp">

<head>
    <title>Dashboard | Dashboard</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="Thu, 19 Nov 1900 08:52:00 GMT">
    <link rel="shortcut icon" href="static/madmin/images/icons/favicon.ico">
    <link rel="apple-touch-icon" href="static/madmin/images/icons/favicon.png">
    <link rel="apple-touch-icon" sizes="72x72" href="static/madmin/images/icons/favicon-72x72.png">
    <link rel="apple-touch-icon" sizes="114x114" href="static/madmin/images/icons/favicon-114x114.png">
    <!--Loading bootstrap css-->
    <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,700">
    <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700,300">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/jquery-ui-1.10.4.custom/css/ui-lightness/jquery-ui-1.10.4.custom.min.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/font-awesome/css/font-awesome.min.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/bootstrap/css/bootstrap.min.css">
    <!--LOADING STYLESHEET FOR PAGE-->
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/intro.js/introjs.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/calendar/zabuto_calendar.min.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/sco.message/sco.message.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/intro.js/introjs.css">
    <!--Loading style vendors-->
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/animate.css/animate.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/jquery-pace/pace.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/iCheck/skins/all.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/jquery-notific8/jquery.notific8.min.css">
    <link type="text/css" rel="stylesheet" href="static/madmin/vendors/bootstrap-daterangepicker/daterangepicker-bs3.css">
    <!--Loading style-->
    <link type="text/css" rel="stylesheet" href="static/madmin/css/themes/style1/orange-blue.css" class="default-style">
    <link type="text/css" rel="stylesheet" href="static/madmin/css/themes/style1/orange-blue.css" id="theme-change" class="style-change color-change">
    <link type="text/css" rel="stylesheet" href="static/madmin/css/style-responsive.css">
    <script src="<%=request.getContextPath() %>/static/madmin/js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/static/My97DatePicker/WdatePicker.js"></script>
	<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/static/madmin/vendors/jquery-toastr/toastr.min.css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/static/layer/layer.js"></script>
</head>

<body class=" ">
    <div>
        <!--BEGIN BACK TO TOP--><a id="totop" href="#"><i class="fa fa-angle-up"></i></a>
        <!--END BACK TO TOP-->
        <!--BEGIN TOPBAR-->
        <div id="header-topbar-option-demo" class="page-header-topbar">
            <nav id="topbar" role="navigation" style="margin-bottom: 0; z-index: 2;" class="navbar navbar-default navbar-static-top">
                <div class="navbar-header">
                    <button type="button" data-toggle="collapse" data-target=".sidebar-collapse" class="navbar-toggle"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                    </button><a id="logo" href="index.html" class="navbar-brand"><span class="fa fa-rocket"></span><span class="logo-text">ÂµAdmin</span><span style="display: none" class="logo-text-icon">Âµ</span></a>
                </div>
                <div class="topbar-main"><a id="menu-toggle" href="#" class="hidden-xs"><i class="fa fa-bars"></i></a>
                    
                    <form id="topbar-search" action="#" method="GET" class="hidden-xs">
                        <div class="input-group">
                            <input type="text" placeholder="Search..." class="form-control" /><span class="input-group-btn"><a href="javascript:;" class="btn submit"><i class="fa fa-search"></i></a></span>
                        </div>
                    </form>
                </div>
            </nav>
        </div>
        <!--END TOPBAR-->
        <div id="wrapper">
            <!--BEGIN SIDEBAR MENU-->
            <nav id="sidebar" role="navigation" class="navbar-default navbar-static-side">
                <div class="sidebar-collapse menu-scroll">
                    <ul id="side-menu" class="nav">
                        <li class="user-panel">
                            <div class="thumb"><img src="" alt="" class="img-circle" />
                            </div>
                            <div class="info">
                                <p>John Doe</p>
                                <ul class="list-inline list-unstyled">
                                    <li><a href="extra-profile.html" data-hover="tooltip" title="Profile"><i class="fa fa-user"></i></a>
                                    </li>
                                    <li><a href="email-inbox.html" data-hover="tooltip" title="Mail"><i class="fa fa-envelope"></i></a>
                                    </li>
                                    <li><a href="#" data-hover="tooltip" title="Setting" data-toggle="modal" data-target="#modal-config"><i class="fa fa-cog"></i></a>
                                    </li>
                                    <li><a href="extra-signin.html" data-hover="tooltip" title="Logout"><i class="fa fa-sign-out"></i></a>
                                    </li>
                                </ul>
                            </div>
                            <div class="clearfix"></div>
                        </li>
                        <li class="active"><a href="#tables"><i class="fa fa-tachometer fa-fw"><div class="icon-bg bg-orange"></div></i><span class="menu-title">卡密信息维护</span></a>
                        </li>
                        <li><a href="#"><i class="fa fa-desktop fa-fw"><div class="icon-bg bg-orange"></div></i><span class="menu-title">订单查询</span></a>
                        <li><a href="#"><i class="fa fa-send-o fa-fw"><div class="icon-bg bg-orange"></div></i><span class="menu-title">商品查询</span></a>
                        <li><a href="#"><i class="fa fa-th-list fa-fw"><div class="icon-bg bg-orange"></div></i><span class="menu-title">会员查询</span></a>
                        <!--li.charts-sum<div id="ajax-loaded-data-sidebar"></div>-->
                    </ul>
                </div>
            </nav>
            <!--END SIDEBAR MENU-->
            <!--BEGIN PAGE WRAPPER-->
            <div id="page-wrapper">
                <!--BEGIN TITLE & BREADCRUMB PAGE-->
                <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
                    <ol class="breadcrumb page-breadcrumb pull-left">
                        <li><i class="fa fa-home"></i>&nbsp;<a href="index.jsp">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
                        <li class="active"><span ng-model="title"></span></li>
                    </ol>
                    <div class="clearfix"></div>
                </div>
                <!--END TITLE & BREADCRUMB PAGE-->
                <!--BEGIN CONTENT-->
                <div class="page-content">
                    <div ng-view></div>
    			</div>
    <!--END CONTENT-->
    </div>
    <!--BEGIN FOOTER-->
    <div id="footer">
        <div class="copyright">2014 Â© &mu;Admin - Responsive Multi-Style Admin Template</div>
    </div>
    <!--END FOOTER-->
    <!--END PAGE WRAPPER-->
    </div>
    </div>
    
    <!--CORE JAVASCRIPT-->
    <script src="../static/madmin/js/main.js"></script>
    <!--LOADING SCRIPTS FOR PAGE-->
    <script src="../static/madmin/js/index.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/static/angularjs/angular.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/static/angularjs/angular-route.min.js"></script>
	
	<script src="<%=request.getContextPath() %>/static/madmin/vendors/jquery-toastr/toastr.min.js"></script>
	<script src="<%=request.getContextPath() %>/static/madmin/vendors/jquery-validate/jquery.validate.min.js"></script>
	<script src="<%=request.getContextPath() %>/static/madmin/js/form-validation.js"></script>
</body>
<script type="text/javascript">
  $(document).ready(function(){
	 
		     var ii = layer.load();
		    //此处用setTimeout演示ajax的回调
		    setTimeout(function(){
		        layer.close(ii);
		    }, 3000); 
		
	  
});   

  function loadLayer(){
		 layer.load();
	};
	function closeLayer(){
		layer.closeAll();
	};
</script>
<script type="text/javascript">

	var myApp = angular.module('myApp',['ngRoute']);
	myApp.config(['$routeProvider','$httpProvider',function($routeProvider,$httpProvider){
		$httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';     
		$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; 
		$httpProvider.defaults.transformRequest = [function(data) { 
		var param = function(obj) {             
			var query = '';             
			var name, value, fullSubName, subName, subValue, innerObj, i;              
			for (name in obj) {                
				value = obj[name];                  
				if (value instanceof Array) {               
					for (i = 0; i < value.length; ++i) {       
						subValue = value[i];               
						fullSubName = name + '[' + i + ']';         
						innerObj = {};             
						innerObj[fullSubName] = subValue;      
						query += param(innerObj) + '&';     
						}                 
					} else if (value instanceof Object) {          
						for (subName in value) {         
							subValue = value[subName];    
							fullSubName = name + '[' + subName + ']';     
							innerObj = {};              
							innerObj[fullSubName] = subValue;    
							query += param(innerObj) + '&';     
							}               
						} else if (value !== undefined && value !== null) {   
							query += encodeURIComponent(name) + '='    
							+ encodeURIComponent(value) + '&';                 
							}           
				}              
			return query.length ? query.substr(0, query.length - 1) : query;    
			};          
			return angular.isObject(data) && String(data) !== '[object File]'? param(data): data;    
			}]; 
		
	
		
		$routeProvider
			.when('/tables',{
				templateUrl:'page/card/tables.html',
				controller:'tableController'
			})
			.when('/addNew/:id',{
				templateUrl:'page/card/add.html',
				controller:'addNewController'
			});
	}]);
	var ii =layer.load(0);
	myApp.controller('tableController', function($scope,$http,BusinessService,$location) {
		
    	
		$scope.currentPage = 1;
	    $scope.totalPage = 1;
	    $scope.pageSize = 10;
	    $scope.pages = [];
	    $scope.endPage = 1;
	    $scope.showNum =10;
	    //获取总流水
	    BusinessService.total().success(function (data) {
	    	
	        $scope.total = data;
	    });
	    
	    BusinessService.list($scope.currentPage, $scope.pageSize).success(function (data) {
	    	
	    	$scope.cards = data;
	    	$scope.totalPage = Math.ceil($scope.total/$scope.pageSize);
	    	//closeLayer();
	    });
	    
	    $scope.load = function () {
	    	
	        BusinessService.list($scope.currentPage, $scope.pageSize).success(function (data) {
	        	
	            $scope.cards = data;
	            //获取总页数
	            //$scope.totalPage = Math.ceil(data.count / $scope.pageSize);
	            $scope.endPage = $scope.totalPage;
	            //生成数字链接
	            if ($scope.currentPage > 1 && $scope.currentPage < $scope.totalPage) {
	                $scope.pages = [
	                    $scope.currentPage - 1,
	                    $scope.currentPage,
	                    $scope.currentPage + 1
	                ];
	            } else if ($scope.currentPage == 1 && $scope.totalPage > 1) {
	                $scope.pages = [
	                    $scope.currentPage,
	                    $scope.currentPage + 1
	                ];
	            } else if ($scope.currentPage == $scope.totalPage && $scope.totalPage > 1) {
	                $scope.pages = [
	                    $scope.currentPage - 1,
	                    $scope.currentPage
	                ];
	            }
	            
	        });
	    };
	 
	    $scope.next = function () {
	    	
	    	
	        if ($scope.currentPage < $scope.totalPage) {
	            $scope.currentPage++;
	            $scope.load();
	            
	        }
	      
	    };
	 
	    $scope.prev = function () {
	    	
	        if ($scope.currentPage > 1) {
	            $scope.currentPage--;
	            $scope.load();
	        }
	        //closeLayer();
	    };
	 
	    $scope.changeShowNum = function (){
	    	
	    	console.log($scope.showNum);
	    	$scope.pageSize=$scope.showNum;
	    	 $scope.load();
	    };
	    $scope.loadPage = function (page) {
	    	
	        $scope.currentPage = page;
	        $scope.load();
	        //closeLayer();
	    };
	    
	    $scope.addNew = function (id){
	    	$location.path("addNew/"+id);
	    }
	    
	    $scope.batchWork = function(){
	    	$http.get('<%=request.getContextPath()%>/card/batchWork').success(function (data){
	    		toastr[data.flag](data.msg, data.title);
			});
	    }
	    
	});

	
	myApp.factory('BusinessService', ['$http', function ($http) {
	
	    var list = function (page, size) {
	        return $http({
	            params: {
	                page: page,
	                size: size
	            },
	            url: '<%=request.getContextPath()%>/card/getOrder'
	        });
	    };
	 
	    var total = function () {
	        return $http.get('<%=request.getContextPath()%>/card/getTotal');
	    };
	 
	    var post = function (business) {
	        return $http.post('/merchants/business/post', business);
	    };
	 
	    return {
	        list: function (page, size) {
	            return list(page, size);
	        },
	        total: function () {
	            return total();
	        },
	        post: function (business) {
	            return post(business);
	        }
	    };
	   
	}]);

	
	myApp.controller("addNewController",function($scope,$http,$location,$routeParams,$window){
		
		$http.get('<%=request.getContextPath()%>/card/updateRow/'+$routeParams.id).success(function (data){
			$scope.cardid = data.id;
			$scope.cardm = data.cardm;
			$scope.indate = data.in_date;
		});
		
		$scope.saveUser = function(){
		
			var pData = {cardid:$scope.cardid,cardm:$scope.cardm};
			$http({
				method:'POST',
				url: '<%=request.getContextPath()%>/card/saveOrder',
				data: pData,
				headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
				
	        }).success(function (data){
	        	layer.close(ii);
				$location.path("tables");
				toastr[data.flag](data.msg, data.title);
			});
		}
		
		$scope.reBack = function(){
			$window.history.back();
		}
		
	});

</script>


</html>